/**
 * ====== 登录 TOKEN ======
 */

const TokenKey = 'APP-AUTH-TOKEN'
const ExpiresTimeKey = "APP-TOKEN-EXPRESS-TIME"
const RefreshTokenKey = 'APP-REFRESH-TOKEN'

/**
 * 获取登录 TOKEN
 */
export const getAccessToken = () => {
    return uni.getStorageSync(TokenKey)
}

/**
 * 设置登录 TOKEN
 */
export const setAccessToken = (token: string) => {
    return uni.setStorageSync(TokenKey, token)
}

/**
 * 获取刷新 TOKEN
 */
export const getRefreshToken = () => {
    return uni.getStorageSync(RefreshTokenKey)
}

/**
 * 设置登录 TOKEN
 */
export const setRefreshToken = (token: string) => {
    return uni.setStorageSync(RefreshTokenKey, token)
}

/**
 * 获取有效时间
 */
export const getTokenExpiresTime = () => {
    return uni.getStorageSync(ExpiresTimeKey)
}

/**
 * 设置有效时间
 */
export const setTokenExpiresTime = (expiresTime: number) => {
    return uni.setStorageSync(ExpiresTimeKey, expiresTime)
}

/**
 * 删除登录 TOKEN
 */
export const removeToken = () => {
    uni.removeStorageSync(TokenKey)
    uni.removeStorageSync(RefreshTokenKey)
    uni.removeStorageSync(ExpiresTimeKey)
}

/**
 * ====== 租户相关 ======
 */

const TenantIdKey = "APP-TENANT-ID"
const VisitTenantIdKey = "APP-VISIT-TENANT-ID"

export const getTenantId = () => {
    return uni.getStorageSync(TenantIdKey)
}

export const setTenantId = (tenantId: number) => {
    uni.setStorageSync(TenantIdKey, tenantId)
}

export const getVisitTenantId = () => {
    return uni.getStorageSync(VisitTenantIdKey)
}

export const setVisitTenantId = (visitTenantId: number) => {
    uni.setStorageSync(VisitTenantIdKey, visitTenantId)
}
